package 二叉树相关问题.BST;

public class 范围和 {
    int sum=0;
    public int rangeSumBST(TreeNode root, int low, int high) {
       traverse(root,low,high);
        return sum;
    }

    private void traverse(TreeNode root,int low,int high) {
        if (root==null)
            return;
        traverse(root.left,low,high);
        if (root.val>=low && root.val<=high)
            sum+=root.val;
        traverse(root.right,low,high);
    }
}
